/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.BatchEntity;
import entity.DataObjectEntity;
import entity.PlannedReserveEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 *
 * @author wei
 */
@Stateless
public class PlannedReserveEntityFacade extends AbstractFacade<PlannedReserveEntity> {
    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public PlannedReserveEntityFacade() {
        super(PlannedReserveEntity.class);
    }
    
      public List findPlannedReservationByProduct(String productName) {
  CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
            javax.persistence.criteria.CriteriaQuery cq = builder.createQuery();
            Root<DataObjectEntity> plannedReserveRoot = cq.from(PlannedReserveEntity.class);
        
            Predicate predicate1 = builder.equal(plannedReserveRoot.get("product").get("productName"), productName);
            Predicate predicate2 = builder.equal(plannedReserveRoot.get("archived"), false);
            
               cq.select(plannedReserveRoot);
               cq.where(builder.and(predicate1, predicate2));
            return new ArrayList(getEntityManager().createQuery(cq).getResultList());
    }
}
